package com.hmall.service;

import com.hdmall.business.common.common.ServerResponse;
import com.hmall.mapper.MallDistmodeMapper;
import com.hmall.model.MallDistmode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 配送
 */
@Service
public class DistModeService {
    private final MallDistmodeMapper distmodeMapper;

    @Autowired
    public DistModeService(MallDistmodeMapper distmodeMapper) {
        this.distmodeMapper = distmodeMapper;
    }

    public ServerResponse<List<MallDistmode>> selectAllDistModes() {
        List<MallDistmode> mallDistmodes= null;
        try {
            mallDistmodes = distmodeMapper.selectAllDistModes();
        } catch (Exception e) {
            e.printStackTrace();
            ServerResponse.createByStatus(300,"配送方式查询失败",null);
        }

        return  ServerResponse.createByStatus(200,"配送方式查询成功",mallDistmodes);
    }

    //修改配送选中状态
    public ServerResponse<Integer> updateCheck(Integer distId, Integer checked){
        int update= 0;
        try {
            update = distmodeMapper.updateCheck(distId,checked);
        } catch (Exception e) {
            e.printStackTrace();
            ServerResponse.createByStatus(300,"配送方式设置失败",null);
        }
        return ServerResponse.createBySuccess("配送方式更新成功",update);
    }
    public ServerResponse<MallDistmode> selectById(Integer distId) {
        MallDistmode mallDistmode= null;
        try {
            mallDistmode = distmodeMapper.selectById(distId);
        } catch (Exception e) {
            e.printStackTrace();
            return  ServerResponse.createByStatus(22,"找不到配送方式",null);
        }
        if (null==mallDistmode){
            return  ServerResponse.createByStatus(22,"找不到配送方式",null);
        }
        return ServerResponse.createBySuccess("配送方式查询成功",mallDistmode);
    }

}
